package service.impl;

import mapper.IUserMapper;
import org.apache.ibatis.session.SqlSession;
import pojo.User;
import service.*;
import utils.MybatisUtils;
import vo.ResponseVo;

import java.util.List;

public class UserService implements IUserService {


    @Override
    public ResponseVo<List<User>> getUserList() {
        //1.调用相关mapper执行操作
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IUserMapper mapper = sqlSession.getMapper(IUserMapper.class);
        List<User> list = mapper.getUserList();
//        list.add(null);
        //2.将结果封装到ResponseVo中返回
        ResponseVo<List<User>> responseVo = new ResponseVo<>();
        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);
        return responseVo;
    }

    @Override
    public ResponseVo<User> findUserById(Integer id) {
        //1.调用相关mapper执行操作
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IUserMapper mapper = sqlSession.getMapper(IUserMapper.class);
        User user = mapper.findUserById(id);

        //2.将结果封装到ResponseVo中返回
        ResponseVo<User> responseVo = new ResponseVo<>();
        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(user);
        return responseVo;
    }

}
